﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OF.Common;
namespace OF.Web
{
    public partial class index : System.Web.UI.Page
    {
        BLL.Addr.AreaCache area_cache = new BLL.Addr.AreaCache();
        List<Model.Seller> list = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //初始化从缓存获取
                string schoolid = WebUtils.GetSchoolCookie();
                if (string.IsNullOrWhiteSpace(schoolid))
                {
                    //参数获取
                    schoolid = Request.QueryString["schoolid"];
                    if (!string.IsNullOrWhiteSpace(schoolid))
                    {
                        WebUtils.AddSchoolCookie(schoolid);
                    }
                }
                if (string.IsNullOrWhiteSpace(schoolid)) {
                    Response.Redirect("/schools.aspx");
                    return;
                }

                list = area_cache.GetSellersBySchoolId(Convert.ToInt32(schoolid));
                BindDate(list);

            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string key = txtkey.Text;
        
            //根据名称
            if (!string.IsNullOrWhiteSpace(key))
            {
               list= area_cache.GetSellersByName(key);
            }//根据学校
            else {
                string schoolid = WebUtils.GetSchoolCookie();
                list= area_cache.GetSellersBySchoolId(Convert.ToInt32(schoolid));
            }

            BindDate(list);
        }

        private void BindDate(List<Model.Seller> list)
        {
            if (list != null)
            {
                rptwmList.DataSource = list.Where(c => (c.order_type == 1 || c.order_type == 3));
                rptwmList.DataBind();

                rptdcList.DataSource = list.Where(c => (c.order_type == 2 || c.order_type == 3));
                rptdcList.DataBind();
            }
            rptwmList.Visible = true;
            rptdcList.Visible = false;
        }

        protected void btnWM_Click(object sender, EventArgs e)
        {
            rptwmList.Visible = true;
            rptdcList.Visible = false;
        }

        protected void btnDC_Click(object sender, EventArgs e)
        {
            rptwmList.Visible = false;
            rptdcList.Visible = true;
        }
   
    
    
    }
}